package com.wenlin.page.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wenlin.page.domain.User;
import com.wenlin.page.mapper.UserMapper;
import com.wenlin.page.response.Message;
import com.wenlin.page.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 *  Created with IntelliJ IDEA.
 *  User:  wenlin
 *  Date:  2017/11/23
 *  Time:  15:36
 *  Description:
 **/
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    /***
     *  User:  wenlin
     *  Date:  2017/12/5
     *  Time:  14:22
     *  Description:pagehelper分页查询
     **/
    @Override
    public Message<PageInfo> selectPage(Integer pageNum, Integer pageSize) {
        //调用pageHelper分页
        //PageHelper.startPage(pageNum,pageSize)方法调用后，后面必须有一个Mapper的查询方法，必须被消费掉。
        //否则会由于ThreadLocal的原因，当该线程被其他方法调用时被分页。
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = userMapper.select();
        return new Message<>(new PageInfo(users));
    }

}
